package com.liury.bbs.utils;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class AdminInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String admin = (String) session.getAttribute("admin");
        if (admin == null) {
            session.setAttribute("msg","请先登录");
            response.sendRedirect("../admin/tologin");
            return false;
        } else {
            return true;
        }
//        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
